package calao.contact.client;

import java.util.Iterator;

import com.google.gwt.user.client.ui.FlowPanel;

import calao.client.Desktop;
import calao.client.ui.HasLinks;
import calao.client.ui.HasTitle;
import calao.client.ui.Link;

public class GroupList 
extends FlowPanel
implements HasLinks, HasTitle
{

	final ContactMod mod = ContactMod.instance;

	GroupList()
	{
		refresh();
	}
	
	public void refresh()
	{
		clear();
		Iterator iter = mod.listGroups();
		while (iter.hasNext()) {
			final Group group = (Group)iter.next();
			add(new Link(group.name) {
				protected void onClick() {
					ContactTable groupTable = new ContactTable(group);
					groupTable.parentGroupList = GroupList.this;
					Desktop.getDesktop().stackView(groupTable); 
				}
			});			
		}
		setTitle(mod.text.groups());
	}

	public Link[] getLinks() {
		if (ContactMod.canModify()) return new Link[] { new Link(mod.text.newGroup()) {
			protected void onClick() {
				Desktop.getDesktop().stackView(new GroupForm(GroupList.this)); 
			}
		}};
		else return new Link[0];
	}

}
